
//
//  ShopViewController.m
//  afn
//
//  Created by mac on 2018/5/7.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "ShopViewController.h"
#import "ShopView.h"

@interface ShopViewController ()
@property(nonatomic,strong)ShopView *aView;
@end

@implementation ShopViewController

- (void)viewDidLoad {
    [super viewDidLoad];
     self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"ico-shoucang"] style:UIBarButtonItemStylePlain target:self action:@selector(CollectionBtn)];
    
    
    _aView=[ShopView new];
    [self.view addSubview:_aView];
    [_aView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.top.mas_equalTo(NAV_HEIGHT);
    }];
    _aView.num=@1;
    _aView.viewController=self;
    [_aView creatView];
    
    [self getData];
    [self getFuWu];
    [self getBarber];
    [self isCollection];
    
}
-(void)isCollection{
    NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:_shop_id,@"id",@"shop",@"type", nil];

    [gongju AFNPOSTDataUrl:@"v1/collection/user-collection" andDic:dic andTableView:nil andViewController:self andSuccessBlock:^(id responseObject) {
        
        if ([responseObject integerValue]==1) {
             self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"ico-shoucang-1"] style:UIBarButtonItemStylePlain target:self action:@selector(CollectionBtn)];
        }
        else{
             self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"ico-shoucang"] style:UIBarButtonItemStylePlain target:self action:@selector(CollectionBtn)];
        }
        
    } anderrorBlock:nil];
}

-(void)getData{
    NSString *url=[NSString stringWithFormat:@"shop/%@",_shop_id];
    NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:_shop_id,@"shop_id", nil];
    [gongju AFNPOSTDataUrl:url andDic:dic andTableView:nil andViewController:self andSuccessBlock:^(id responseObject) {
     
        self->_aView.model=[ShopModel mj_objectWithKeyValues:[responseObject objectForKey:@"shop"]];
        self->_aView.shop_service=[responseObject objectForKey:@"shop_service"];
        self->_aView.talkArr=[responseObject objectForKey:@"talk_list"];
        self.navigationItem.title=self->_aView.model.shop_name;
        [self->_aView.tableView reloadData];
        
    } anderrorBlock:nil];
}

-(void)CollectionBtn{
    NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:@"shop",@"type",_shop_id,@"add_id", nil];
    [gongju AFNPOSTDataUrl:@"v1/collection/add-collection" andDic:dic andTableView:_aView.tableView andViewController:self andSuccessBlock:^(id responseObject) {
        [gongju svpInfo:[responseObject objectForKey:@"msg"]];
        if ([[responseObject objectForKey:@"msg"] isEqualToString:@"已取消该店铺的收藏"]) {
             self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"ico-shoucang"] style:UIBarButtonItemStylePlain target:self action:@selector(CollectionBtn)];
        }else{
             self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"ico-shoucang-1"] style:UIBarButtonItemStylePlain target:self action:@selector(CollectionBtn)];
        }
        
    } anderrorBlock:nil];
    
    
}
-(void)getFuWu{
    NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:_shop_id,@"shop_id",@"100",@"number", nil];
    [gongju AFNPOSTDataUrl:@"v1/hairdresser/hairdresser-list" andDic:dic andTableView:nil andViewController:self andSuccessBlock:^(id responseObject) {
        
        self->_aView.fuWuArr=responseObject ;
        [self->_aView.tableView reloadData];
    } anderrorBlock:nil];
}
-(void)getBarber{
    NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:_shop_id,@"shop_id",@"0",@"number", nil];
    [gongju AFNPOSTDataUrl:@"v1/barber/barber-list" andDic:dic andTableView:nil andViewController:self andSuccessBlock:^(id responseObject) {
        self->_aView.barBerArr=responseObject ;
        [self->_aView.tableView reloadData];
    } anderrorBlock:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
